<?php
/**
 * 资金流水
 * @return
 * @author yuncran@126.com
 */

namespace app\api\listener;

use app\model\UserMoneyLogModel;

class UserMoney
{

    public function handle($param)
    {
        try {
            $data = array_merge([
                'createtime' => time(),
                'memo' => self::getType($param['type'])
            ], $param);
            if ($param['money'] > 0) {
                UserMoneyLogModel::create($data);
            }
        } catch (\Exception $e) {
            return ($e->getMessage() . $e->getLine());
        }
        return true;
    }


    public static function getType($type)
    {
        if ($type == 0) {
            $memo = '购买翻译包';
        } elseif ($type == 1) {
            $memo = '赠送礼物';
        } elseif ($type == 2) {
            $memo = '赠送金币';
        } elseif ($type == 3) {
            $memo = '翻译消耗';
        } elseif ($type == 4) {
            $memo = '金币充值';
        } else {
            $memo = '';
        }
        return $memo;
    }

}